﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Terminal.Advanced_AEUC_settings_controls.Settings_AUX;

namespace Terminal.Advanced_AEUC_settings_controls.Scripting
{
    class ScrStrCmp : ScrBasicAction
    {
        /// <summary>
        /// Public constructor for the script action
        /// </summary>
        /// <param name="iDispName">Action display text</param>
        /// <param name="iUsageHelp">Usage help and comments text for the action</param>
        public ScrStrCmp(string iDispName, string iUsageHelp)
            : base(iDispName, iUsageHelp)
        {
            usageHelp += "Input params: String compare value 1 + String compare value 2\n";
        }

        /// <summary>
        /// Perform the action using specified parameters.
        /// </summary>
        /// <param name="paramList">List of the input/output parameters for the action</param>
        /// <returns>True if action is succesful</returns>
        public override bool Do(List<object> paramList)
        {
            if (breakPoint)
                WaitUserInput();

            if (paramList.Count > 2 && paramList[0].GetType() == typeof(ScrRunTimeEnv) && paramList[1].GetType() == typeof(char[]) && paramList[1].GetType() == typeof(char[]))
            {
                ScrRunTimeEnv rte = (ScrRunTimeEnv)(paramList[0]);
                char[] cmpVal1 = (char[])(paramList[1]);
                char[] cmpVal2 = (char[])(paramList[2]);
                Boolean compResult = true;

                if (cmpVal1.Length == cmpVal2.Length)
                {
                    for (int i = 0; i < cmpVal1.Length; i++)
                    {
                        if (cmpVal1[i] != cmpVal2[i])
                        {
                            compResult = false;
                            break;
                        }
                    }
                }
                else
                {
                    compResult = false;
                }

                if (compResult)
                    rte.condExecution = ScrRunTimeEnv.CondExecMode.EXEC_IF;
                else
                    rte.condExecution = ScrRunTimeEnv.CondExecMode.SKIP_IF;

                return true;
            }

            return false;
        }
        /// <summary>
        /// Returns a List containing objects of the parameter list required for the Do function.
        /// </summary>
        /// <returns>List of parameter objects</returns>
        public override List<Type> GetParamList()
        {
            List<Type> paramList = new List<Type>();
            paramList.Add(typeof(ScrRunTimeEnv));
            paramList.Add(typeof(char[]));
            paramList.Add(typeof(char[]));

            return paramList;
        }
    }
}
